<%@page language="java" contentType="text/html; charset=utf-8"	pageEncoding="utf-8"%>
<html>
<head>
<script type="text/javascript">
var listUrl="rest/monitor/list.do";
var monitorStatusJson;         
 
$(document).ready(function () {

	var villageJson=syncGetDictListByTypeName('village');
	console.log(villageJson);
	  
	$('#village').combobox({
          data: villageJson,
          valueField: 'dictValue',
          textField: 'dictName',
          onLoadSuccess: function(param){
        	  $('#village').combobox('setValue','');
    		}
          
    });  
	
/* 	
 */
 
	/*  $('#month').combobox('setValue','11');//设置默认值为今年 */

    $("#submit-search").click(function () {
        $('#monitor-dg').datagrid({ queryParams: form2Json("fms") });   //点击搜索
    });

    $("#monitor-dg").datagrid({
        loadMsg: '数据加载中....',
        //title: '用户管理',
        //height:document.body.clientHeight-60,
        width: '100%',
        url: listUrl,        
// 		loadFilter : function(result) {
// 				if (result.retCode == '0000') {
// 					return result.data;
// 				} else {
// 					return result.retMsg;
// 				}
// 			},
			nowrap : false,
			striped : true,
			remoteSort : false,
			rownumbers : true,
			pagination : true,
			fitColumns : true,
			pageList : [ 10, 15, 20, 25  ],
			frozenColumns : [ [ {
				field : 'id',
				checkbox : true
			}, {
				title : '编号',
				field : 'id',
				width : 0,
				hidden : 'true'
			} ] ],
			
			columns : [ [
			{
				field : 'name',
				title : '户名',
				width : 30
			},	
			{
				field : 'masterName',
				title : '户主名',
				width : 30
			},
			
			{
				field : 'village',
				title : '村',
				width : 50
			},
			{
				field : 'meterNo',
				title : '电机编号',
				width : 50
			},
			{
				field : 'phone',
				title : '联系电话',
				width : 40
			},
			
			{
				field : 'registeredTime',
				title : '安装时间',
				width : 50
			}, 
			 {
				field : 'opt',
				title : '操作',
				width : 180,
				align : 'center',
				formatter: function(value,row,index){
					/* if(row.status == 1){
						return "<a href='javascript:stateChange("+row.id+",0);'>详情</a>";
					}else if(row.status==0){
						return "<a href='javascript:stateChange("+row.id+",1);'>详情</a>";;
					} */
					var  buttons="<a href='javascript:showCenter(\"air-monitor/index.do?family_id="+row.id+"\" ,0);'>实时室温</a>&nbsp&nbsp&nbsp&nbsp"+
					"<a href='javascript:showCenter(\"water-monitor/index.do?family_id="+row.id+"\" ,0);'>实时进出水温度</a>&nbsp&nbsp&nbsp&nbsp"+
					"<a href='javascript:showCenter(\"day-electric-monitor/index.do?family_id="+row.id+"\" ,0);'>日用电量</a>&nbsp&nbsp&nbsp&nbsp"+
					"<a href='javascript:showCenter(\"mouth-electric-monitor/index.do?family_id="+row.id+"\" ,0);'>月用电量</a>&nbsp&nbsp&nbsp&nbsp";
					return buttons;
				}
			}  

			] ]
		});// end datagrid
		//设置分页控件
		var p = $('#monitor-dg').datagrid('getPager');
		$(p).pagination({
			pageSize : 10,//每页显示的记录条数，默认为10
			pageList : [ 10, 15, 20, 25 ],//可以设置每页记录条数的列表
			beforePageText : '第',//页数文本框前显示的汉字
			afterPageText : '页    共 {pages} 页',
			displayMsg : '当前显示 {from} - {to} 条记录   共 {total} 条记录',
			onBeforeRefresh : function() {
				$(this).pagination('loading');
				$(this).pagination('loaded');
			}

		});//end pagination

	})
	//end ready
	
	
	/* function stateChange(id,status){
		$.post("rest/monitorUpdate.do",{"id":id,"status":status},function(data){
			if(data.retCode=="0000"){
				$('#monitor-dg').datagrid("reload");
			}
		});
		
	} */
	
	
	
	function uploadexcel() {
		var url = "monitor/upload.do";
		$.post(url, {}, function(data) {
			$("#center").empty();
			$("#center").html(data);
			$.parser.parse($("#center"));
		});
	}
	
	function editFamily() {
		var rows = $('#monitor-dg').datagrid('getSelections');
		if (rows.length != 1) {
			$.messager.alert('操作提示', "请先选择一条要编辑的信息！");
			return;
		}
		var row = $('#monitor-dg').datagrid('getSelected');
		var id = row.id;
		var url = "monitor/edit.do";
		$.post(url, row, function(data) {
			$("#center").empty();
			$("#center").html(data);
			$.parser.parse($("#center"));
		});
	}

	function removeFamily() {
		var array = $('#monitor-dg').datagrid('getSelections');
		var ids = new Array();

		for ( var i = 0; i < array.length; i++) {//组成一个字符串，ID主键之间用逗号隔开
			
			ids[i] = array[i].id;
		}

		ids = ids.join(',');

		if (array != "") {
			$.messager.defaults = {
				ok : "确定",
				cancel : "取消"
			};
			$.messager.confirm('操作提示', '是否要删除该信息？', function(r) {
				if (r) {
					$.post('rest/monitorDel.do', {
						ids : ids
					}, function(response) {

						if (response.retCode == "0000") {
							$('#monitor-dg').datagrid('reload');
							$.messager.alert('操作提示', "删除成功", 'info');							
						} else {
							$.messager.alert('操作提示', "删除失败", 'error');
						}
					});
				}
			});
		} else {
			$.messager.alert('操作提示', "请先选择要删除的信息！");
		}

	};
	
	
</script>
</head>
<body>



<!-- 		<div class="breadcrumb">系统 &gt;&gt; 用户管理</div> -->
		<!-- <div class="breadcrumb">系统 &gt;&gt; 用户管理</div> -->
		<div class="linkbar"><a>监控平台</a>/<a>家庭和电机管理</a></div>
		<div class="formtoolbar">
		<form id="fms" method="post" novalidate>
			    <i>村</i> 
				<select id="village" name="village" class="easyui-combobox" style="width:100px" >
				</select> 
				<i>户主</i> 
				<input id=master name="master" style="width:100px" />

				<a id="submit-search" class="easyui-linkbutton">搜索</a>						
			</form>
		</div>
	</div> 
		<div class="clear"></div>
		<div id="monitor-dg" toolbar="#toolbar"></div>

		<div id="toolbar">
			<!-- <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true"	onclick="newUser()">添加</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">编辑</a> -->
			 
 			
 			
		</div>
</body>
</html>